package BookManager;

import java.lang.StringBuffer;
import java.io.*;
import java.util.Scanner;


public class RandomStringGenerator {
    private static char availableChars[] = {'a','b','c','d','e','f','g','h','i','j',
    'k','l','m','n','n','o','p','q','r','s','t','u','v','w','x','y','z'};
    private String[] myStrings;
    private int numStrings;
 
    public static String GenerateString(int min, int max) {
         StringBuffer sb = new StringBuffer();
         int length = 0;
         
         java.util.Random r = new java.util.Random();
         
         length = r.nextInt(max);
         if (length < min) length = min;
         
         while(sb.length() < length) {
             int nextChar = r.nextInt(availableChars.length - 1);
             sb.append(availableChars[nextChar]);
         }
        
         return sb.toString();
    }
    
    public RandomStringGenerator(String filename) throws IOException {
	File f1 = new File(filename);
    
	Scanner in = new Scanner(f1);
	
	numStrings = 1;
	while(in.hasNextLine()) {
	    in.nextLine();
	    numStrings++;
	}
	myStrings = new String[numStrings];
	
	in = new Scanner(f1);
	int i = 0;
	while(in.hasNextLine()) {
	    i++;      
	    myStrings[i] = in.nextLine();
	}
    }
    
    public String getRandomString() {
	java.util.Random r = new java.util.Random();
	
	return myStrings[Math.abs(r.nextInt()) % numStrings];
    }
    
}
    
